<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>test</title>
  </head>
  <body>
    <div id="test">
      <div id="children1">this is children1</div>
      <div id="children2">this is children2</div>
      <div id="children3">this is children3</div>
    </div>

    <input type="password" id="pwd" value="" /><span onclick="see()">o</span>

    <input type="datetime-local" id="time" value="2021-12-02T20:21:12" />

    <script>
      
      //document整个页面,树

      //id获取,唯一值
      // const h =  document.getElementById('test')

      // //node  element每个节点的对象

      // //根据类获取,多个点
      // document.getElementsByClassName()

      // //标签名  ,多个
      // document.getElementsByTagName()

      //css的选择器的规则去选择
      //单个获取,只获取一个node
      // const test = document.querySelector("#test")

      // //多个获取,获取的时nodeList
      // const divList = document.querySelectorAll("#test div")

      // divList[0].innerHTML = "<h1>change</h1>"

      // for (let index = 0; index < divList.length; index++) {

      //     const element = divList[index];

      //     console.log(element.innerHTML += `<h1>${index}</h1>`)

      // }

      // // test.innerText ="<h1>hhhhhh</h1>"
      // test.innerHTML += '<div id = "children2"> this is children2</div>'

      // console.log(divList);

     
      setInterval(() => {
        const time = document.querySelector("#time");

        let now = new Date();

        // 获取年月日时分秒
        let year = now.getFullYear();
        let month = (now.getMonth() + 1).toString().padStart(2, "0"); // 月份是从0开始的，因此要加1
        let day = now.getDate().toString().padStart(2, "0");
        let hours = now.getHours().toString().padStart(2, "0");
        let minutes = now.getMinutes().toString().padStart(2, "0");
        let seconds = now.getSeconds().toString().padStart(2, "0");

        // 拼接成指定格式的字符串
        let dateTimeString = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;

        time.value = dateTimeString;
      }, 1000);

      function padWithZero(number, width) {
        // 将数字转换为字符串
        let numberString = number.toString();
        // 计算需要添加的零的数量
        let zeroPadding = width - numberString.length;

        // 添加零并返回结果
        return "0".repeat(Math.max(0, zeroPadding)) + numberString;
      }
    </script>
  </body>
</html>
